package com.wang.tool.valve.strategy;


import com.wang.tool.monitor.LinkLogUtil;
import com.wang.tool.monitor.core.MonitorInfo;
import com.wang.tool.valve.Valve;

/**
 * @Description 策略超类
 * @Author shaopeng
 * @Date 2021/7/21
 * @Version 1.0
 */
public abstract class AbsValve implements Valve {

    @Override
    public final boolean isPass(Object param) {
        try {
            return internalIsPass(param);
        } catch (Exception e) {
            LinkLogUtil.newTagLog("isPassError")
                    .v2(e.getClass().getSimpleName())
                    .addAttachment(MonitorInfo.PARAM, param)
                    .addAttachment(MonitorInfo.ERROR, e)
                    .log();
            return false;
        }
    }

    /**
     * 判断是否通过
     *
     * @param param
     * @return
     * @throws Exception 判断异常
     */
    protected abstract boolean internalIsPass(Object param) throws Exception;
}
